import 'package:flutter_base/common/utils/utils.dart';
import 'package:date_format/date_format.dart';
import 'package:flutter/material.dart';
import 'package:flutter_picker/flutter_picker.dart';
Future<String> showPickerDate(BuildContext context,{type =PickerDateTimeType.kYMD ,DateTime? minValue,DateTime? maxValue,String? value}) async {
  String? result;
  await Picker(
      height: 220,
      itemExtent: 38,
      adapter: DateTimePickerAdapter(
        type: type,
        isNumberMonth: true,
        yearSuffix: "年",
        monthSuffix: "月",
        daySuffix: "日",
        minValue: minValue,
        maxValue: maxValue,
        // minHour: 8,
        // maxHour: 19,
        // yearBegin: 1950,
        // yearEnd: 1998,
      ),

      onConfirm: (Picker picker, List value) {
        if(type ==PickerDateTimeType.kYMD){
          result = formatDate((picker.adapter as DateTimePickerAdapter).value!,
              [yyyy, '-', mm, '-', dd]);
        }else if (type ==PickerDateTimeType.kHM){
          result =formatDateStr((picker.adapter as DateTimePickerAdapter).value.toString(),format: 'HH:mm');
        }else{
          result = formatDate((picker.adapter as DateTimePickerAdapter).value!,
              [yyyy, '-', mm, '-', dd]);
        }
        // result = formatDate((picker.adapter as DateTimePickerAdapter).value,
        //     [yyyy, '-', mm, '-', dd]);

        print((picker.adapter as DateTimePickerAdapter).value.toString());
      }).showModal(context);
  return result ?? value??'';
}
Future<String> showPickerMonth(BuildContext context) async {
  String? result;
  await Picker(
      height: 220,
      selecteds: [DateTime.now().month-1],
      itemExtent: 38,
      adapter: PickerDataAdapter<String>(pickerdata: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月']),
      onConfirm: (Picker picker, List value) {

        result = picker.getSelectedValues()[0];
      }).showModal(context);
  return result ?? "";
}
Future<dynamic> showPicker(List? options, BuildContext context) async {
  var result;
  await Picker(
      height: 220,
      itemExtent: 38,
      adapter: PickerDataAdapter<dynamic>(pickerdata: options),
      onConfirm: (Picker picker, List value) {
        result = options![value.first];
      }).showModal(context);
  return result ?? "";
}